//
//  SettingViewController.m
//  ChunLaiZhuangClient
//
//  Created by zzs on 16/3/5.
//  Copyright © 2016年 CLZ. All rights reserved.
//

#import "SettingViewController.h"
#import "CustomSettingHeadTableViewCell.h"
#import "CustomSettingTableViewCellOne.h"
#import "CustomSettingTableViewCellTwo.h"
#import "ResetPassordViewController.h"
#import "ApiClient+Ext.h"
#import "AppContext.h"
#import "AccountManager.h"
#import "TuCaoViewController.h"
@interface SettingViewController ()<UITableViewDataSource,UITableViewDelegate>{
    NSArray *titleArray;
}

@end

@implementation SettingViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNaviTitle:@"设置"];
    [self setNaviLeftButton:@""];
    [self.view addSubview:self.displayView];
    titleArray=[NSArray arrayWithObjects:@"请尽情吐槽我们吧",@"服务协议",@"帮助",@"",@"重置密码",@"",@"退出登录", nil];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(UITableView*)displayView{
    if (!_displayView) {
        _displayView=[[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
        _displayView.delegate=self;
        _displayView.dataSource=self;
        _displayView.backgroundColor=[UIColor clearColor];
        _displayView.bounces=NO;
        _displayView.tableFooterView=[[UIView alloc] initWithFrame:CGRectZero];
        // [_displayView setSeparatorColor:[UIColor redColor]];
    }
    return _displayView;
}
#pragma mark-UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 8;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            static NSString *identifier = @"CustomSettingHeadTableViewCell";
            CustomSettingHeadTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:
                                                identifier];
            if (cell == nil) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomSettingHeadTableViewCell"  owner:self options:nil] lastObject];
                
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
            return cell;
 
        }
            break;
        case 1:
        case 2:
        case 3:
        case 5:
        case 7:
        {
            static NSString *identifier = @"CustomSettingTableViewCellOne";
            CustomSettingTableViewCellOne* cell = [tableView dequeueReusableCellWithIdentifier:
                                                    identifier];
            if (cell == nil) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomSettingTableViewCellOne"  owner:self options:nil] lastObject];
                
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            if (indexPath.row==3 ||indexPath.row==6||indexPath.row==8) {
                [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
            }
          
            cell.contentLabel.text=titleArray[indexPath.row-1];
            return cell;
        }
            break;
        case 4:
        case 6:
        {
            static NSString *identifier = @"CustomSettingTableViewCellTwo";
            CustomSettingTableViewCellTwo* cell = [tableView dequeueReusableCellWithIdentifier:
                                                   identifier];
            if (cell == nil) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomSettingTableViewCellTwo"  owner:self options:nil] lastObject];
                
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
            return cell;
 
        }
            
        default:
            return nil;
            break;
    }
    
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (indexPath.row) {
        case 0:
            return 132;
            break;
        case 1:
        case 2:
        case 3:
        case 5:
        case 7:
            return 44;
            break;
        case 4:
        case 6:
            return 5;
            break;
        default:
            return 0;
            break;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 1:
        {
            //吐槽
            TuCaoViewController *tucaoVC=[[TuCaoViewController alloc] init];
            [self.navigationController pushViewController:tucaoVC animated:YES];
            
        }
            break;
        case 2:
        {
            //服务协议
            CLZWebviewViewController *webVC=[[CLZWebviewViewController alloc] init];
            webVC.webTitle=@"服务协议";
            webVC.webUrl=[NSString stringWithFormat:@"%@%@",DOMAIN_ADDRESS,URL_SERVICE_PROTOCOL];
            [self.navigationController pushViewController:webVC animated:YES];
            
        }
            break;
        case 3:
        {
            //帮助
            CLZWebviewViewController *webVC=[[CLZWebviewViewController alloc] init];
            webVC.webTitle=@"帮助";
            webVC.webUrl=[NSString stringWithFormat:@"%@%@",DOMAIN_ADDRESS,URL_HELP];
            [self.navigationController pushViewController:webVC animated:YES];

        }
            break;
        case 5:
        {
            //重置密码
            ResetPassordViewController *resetVC=[[ResetPassordViewController alloc] init];
            [self.navigationController pushViewController:resetVC animated:YES];
            
        }
            break;
        case 7:
        {
            //退出登录
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"确定退出登录吗？" message:nil delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是", nil];
            [alert show];
            break;
        }
            break;
              default:
            break;
    }
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==1) {
        [self logout];
    }
}
- (void)logout {
     [[LKDHud shareHud] showLoadingView];
    [ApiClient loginOutDidFinishLoaded:^(KXJson *json, NSString *path) {
        NSString *status = [json getStringForKey:@"status"];
         [[LKDHud shareHud] hideLoadingView];
        if ([status isEqualToString:@"1"]) {
            [APP_CONTEXT.accountManager logout];
            [self.navigationController popViewControllerAnimated:YES];
          //  [[LKDHud shareHud] showtip:@"成功推出登陆"];
        }
    } didFailLoaded:^(NSError *error, NSString *path) {
        [[LKDHud shareHud] hideLoadingView];
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
